/*
Simple Forum Auto Poster.
Copyright (C) 2011 Gianni Van Hoecke.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package domain.ui;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 *
 * @author Gianni Van Hoecke <gianni.vh@gmail.com>
 */
public class LookAndFeel implements Serializable
{
    private Map<String, String> jTattoo;
    private String[] lookAndFeels;
    private String selectedLookAndFeel;

    public LookAndFeel()
    {
        LookAndFeelInfo[] lafia = UIManager.getInstalledLookAndFeels();
        this.initMap();
        
        this.lookAndFeels = new String[lafia.length + this.jTattoo.size()];

        //Add installed LAF.
        int i;
        for(i = 0; i < lafia.length; i++)
        {
            LookAndFeelInfo lafi = lafia[i];
            this.lookAndFeels[i] = lafi.getName();
            if(lafi.getClassName().equals(UIManager.getSystemLookAndFeelClassName()))
                this.selectedLookAndFeel = lafi.getName();
        }

        //Add custom LAF.
        Iterator itr = this.jTattoo.keySet().iterator();
        while(itr.hasNext())
        {
            String s = (String)itr.next();
            this.lookAndFeels[i] = s;
            i++;
        }

        if(this.selectedLookAndFeel == null)
            this.selectedLookAndFeel = this.lookAndFeels[0];
    }

    /**
     * Initializes the jTattoo LAF's.
     */
    private void initMap()
    {
        this.jTattoo = new HashMap<String, String>();
        this.jTattoo.put("Acrylic", "com.jtattoo.plaf.acryl.AcrylLookAndFeel");
        this.jTattoo.put("Aero", "com.jtattoo.plaf.aero.AeroLookAndFeel");
        this.jTattoo.put("Aluminium", "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
        this.jTattoo.put("Bernstein", "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
        this.jTattoo.put("Fast", "com.jtattoo.plaf.fast.FastLookAndFeel");
        this.jTattoo.put("Graphite", "com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
        this.jTattoo.put("HiFi", "com.jtattoo.plaf.hifi.HiFiLookAndFeel");
        this.jTattoo.put("Luna", "com.jtattoo.plaf.luna.LunaLookAndFeel");
        this.jTattoo.put("McWin", "com.jtattoo.plaf.mcwin.McWinLookAndFeel");
        this.jTattoo.put("Mint", "com.jtattoo.plaf.mint.MintLookAndFeel");
        this.jTattoo.put("Noire", "com.jtattoo.plaf.noire.NoireLookAndFeel");
        this.jTattoo.put("Smart", "com.jtattoo.plaf.smart.SmartLookAndFeel");
    }
    
    /**
     * @param name The name of the LAF.
     * @return The class name of the LAF. The System LAF is returned when name is invalid.
     */
    public String getClassNameFromName(String name)
    {
        //Look in installed LAF.
        for(LookAndFeelInfo lafi : UIManager.getInstalledLookAndFeels())
            if(lafi.getName().equals(name))
                return lafi.getClassName();

        //Look in jTattoo LAF.
        if(this.jTattoo.containsKey(name))
            return this.jTattoo.get(name);

        return UIManager.getSystemLookAndFeelClassName();
    }

    public String[] getLookAndFeels()
    {
        return lookAndFeels;
    }

    public String getSelectedLookAndFeel()
    {
        return selectedLookAndFeel;
    }

    public void setSelectedLookAndFeel(String selectedLookAndFeel)
    {
        this.selectedLookAndFeel = selectedLookAndFeel;
    }
}